package com.example.hqpatrol.entity.item;

import com.example.hqpatrol.entity.patrol.PatrolDetail;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.StrUtil;

public class PatrolUserSelectItem {

    private String id;
    private String name;

    public PatrolUserSelectItem(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static List<PatrolUserSelectItem> getList(PatrolDetail patrolDetail) {
        List<PatrolUserSelectItem> list = new ArrayList<>();
        String ids = patrolDetail.getUserId();
        String names = patrolDetail.getUserName();
        if(StrUtil.isNotBlank(ids) && StrUtil.isNotBlank(names)){
            List<String> idList = StrUtil.split(ids, ",");
            List<String> nameList = StrUtil.split(names, ",");
            if(idList.size() == nameList.size()){
                list.add(new PatrolUserSelectItem("", "请选择"));
                for(int i=0;i<idList.size();i++){
                    list.add(new PatrolUserSelectItem(idList.get(i), nameList.get(i)));
                }
            }
        }
        return list;
    }

    @Override
    public String toString() {
        return name;
    }
}
